using System;
using System.Collections;
using AutoMapper;
using NHibernate;
using NHibernate.SqlCommand;
using NHibernate.Type;
using Webshop20.Domain.Catalog.Core;
using Tools.Common.ServiceLocator;
using Webshop20.Domain.Customers.Services.Contracts;
using Webshop20.Application.Mappings;

namespace Webshop20.Infrastructure.Persistence.NH.Interceptors
{
    public class VisitorInterceptor : EmptyInterceptor 
    {

        public override bool OnLoad(object entity, object id, object[] state, string[] propertyNames, NHibernate.Type.IType[] types)
        {

            if (entity is Visitor)
            {
                new MappingConfiguration();
                var visitor = entity as Visitor;
                var customerInformationService
                    = ServiceLocator.Current.Resolve<ICustomerInformationService>();
                var customerInformation =
                    customerInformationService.GetCustomerById(visitor.Id);
                visitor = Mapper.Map(customerInformation, visitor);
            }

            return base.OnLoad(entity, id, state, propertyNames, types);
        }
        
    }
}